import * as THREE from 'three';

const MODE_CHOSE = 0;

// 自定义几何体 ---顶点位置数据解析渲染---
function testBufferGeometry(scene) {
    // --------------------- 顶点位置数据解析 ---------------------
    // 创建一个空的几何体对象
    const geometry = new THREE.BufferGeometry();
    // 顶点坐标
    const vertices = new Float32Array([
        0, 0, 0, //顶点1坐标
        50, 0, 0, //顶点2坐标
        0, 100, 0, //顶点3坐标
        0, 0, 10, //顶点4坐标
        0, 0, 100, //顶点5坐标
        50, 0, 10, //顶点6坐标
    ]);
    // 顶点索引 
    const indices = new Uint32Array([0, 1, 2, 0, 2, 3]);
    // 三个一组 表示一个顶点的xyz坐标
    let attribute = new THREE.BufferAttribute( vertices, 3 );
    // 设置几何体attributes 属性的 position属性
    geometry.attributes.position = attribute;

    // 三角面(网格) 渲染模式
    let material = new THREE.MeshBasicMaterial({
        color: 0x0000ff,
        side: THREE.DoubleSide //两面可见
    });
    let mesh = new THREE.Mesh( geometry, material ); // 网格模型对象
    // scene.add( mesh ); // 网格模型添加到场景中

    // 点模式
    let material_points_mode = new THREE.PointsMaterial({
        color: 0xff0000,
        size: 1.0 // 点对象像素尺寸
    });
    let mesh_points = new THREE.Points( geometry, material_points_mode );
    scene.add( mesh_points );

    // 线模式
    let material_line_mode = new THREE.LineBasicMaterial({
        color: 0xff0000,
    });
    let mesh_line = new THREE.Line( geometry, material_line_mode );
    scene.add( mesh_line );
}

function testFuncSetInterval(){
    setInterval( testPrintSomething, 1000 );
}

function testPrintSomething() {
    console.log( "aaaaaaaaaaaaaaaaaaaaa" );
}

const TestBufferGeometry = {
    testBufferGeometry,
    testFuncSetInterval
}

export default TestBufferGeometry;